"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Locker {
    constructor(amount) {
        this.amount = amount;
        this.lens = 0;
        this.delayArray = [];
    }
    lock() {
        if (this.lens < this.amount) {
            this.lens++;
            return new Promise(resolve => {
                resolve();
            });
        }
        else {
            return new Promise(resolve => {
                this.delayArray.push(resolve);
            });
        }
    }
    release() {
        if (this.delayArray.length) {
            this.delayArray.shift()();
        }
        else {
            this.lens--;
        }
    }
}
exports.default = Locker;
